$().ready(function(){
	function getName(str){
		var name=str.splice("_")[0];
		return str;
	}
	var sport=["","Kraken","Binance","P网"];
	$.ajax({
		url:"/app/user_quotation/queryselect",
		success:function(r){
			console.log("init",r);
			$(".loading-box").css("display","none");
			if(r.code==0){
				var data=r.list,html="";
				for(var i=0,len=data.length;i<len;i++){
					var nameType=data[i].type;
					html+="<li data-type="+data[i].id+"><div class='pull-left'><p>"+data[i].qname+"</p><p class='font-white'>"+sport[nameType]+"</p></div><div class='choose-act'><span class='icon'><img src='../../img/clorm.png'></span><span class='icon icon-sort'><img src='../../img/sort.png'></span></div></li>"
				}
				$(".riches-edit-box").empty().html(html);
			}else{
				alert(r.msg);
			}
		}
	})
})
$().ready(function(){
    var pageTop=null;
   $(".riches-edit-box").on("touchstart","li",function(e){
        e.stopPropagation();
       pageTop=$(this).offset().top;
    })
    $(".riches-edit-box").on("touchmove","li",function(e){
        e.stopPropagation();
        var touchTop=e.changedTouches[0].pageY;
         var movePageTop=$(this).offset().top;
        var top=touchTop-movePageTop;
       $(this).css("top",top);
    })
    $(".riches-edit-box").on("touchend","li",function(e){
        e.stopPropagation();
        var height=e.changedTouches[0].pageY;
        var movePageTop=$(this).offset().top;
        $(this).prev()//前一个元素
        var that=$(this);
        var thisIndex=that.index();
       var ulTop= $(".riches-edit-box").offset().top,ulHeight=parseInt($(".riches-edit-box").css("height"));
        //如果在父容器范围内 就移除
        if(movePageTop<(ulTop+ulHeight)&&movePageTop!==pageTop){
            $(".riches-edit-box li").eq(thisIndex).remove();
        }else{
           // console.log("no move")
        }
        $(".riches-edit-box li").map(function(){
            var liTop=$(this).offset().top;
            var liHeight=parseInt($(this).css("height"));
            var liLimit=liTop-liHeight;
            if(liLimit<movePageTop&&movePageTop<liTop){
                that.css("top",0);
                $(this).before(that);
            }else if(movePageTop>(ulTop+ulHeight)){
            	that.css("top",0);
                $(".riches-edit-box").append(that);
            }else{
            	that.css("top",0);
            	$(".riches-edit-box").append(that);
            }
            
        })
        var dataSort=[];
        $(".riches-edit-box li").map(function(index){
        	dataSort[index]={};
        	dataSort[index].sort=index;
        	dataSort[index].id=$(this).data("type");
        })
        //console.log("重新排序",dataSort);
        $.ajax({
			url:'/app/user_quotation/sortsetting',
		    data:{"list":JSON.stringify(dataSort)},    //参数值
		    type:"POST",   //请求方式
		    success:function(r){}
		});
    })
})
